PersonPanel = function(){
	var this_panel = this;

	this.listeners = {
			show : function(){
				this_panel.store.reload();
				settingPersonWindow.reload();
			}
	}
	
	var remove = function(){
		Ext.MessageBox.confirm("确认","确认删除员工账号?",function(btn){
			if(btn == "yes"){
				var recs = this_panel.selModel.getSelections();
				var array = new Array();
				Ext.each(recs,function(rec,i){
					array.push(rec.get("id"));
				});
				var str = array.join(",");
				Ajax({
					url : "person/delete.action",
					params : {ids:str},
					maskTarget : this_panel,
					grid : this_panel
				});
			}
		});
	};
	
	var sm = new Ext.grid.CheckboxSelectionModel({
		listeners : {
			selectionchange : function(){
				var num = this_panel.getSelectionModel().getSelections().length;
				this_panel.deleteButton.setDisabled(num==0);
				this_panel.setButton.setDisabled(num!=1);
			}
		}
	});
	
	var store = new Ext.data.JsonStore({
		url : "person/findForPaging.action",
		root: 'persons',
        totalProperty: 'totalCount',
		baseParams : {start:0, limit:20},
		fields : [ "id","name","supportType","manager.name","manager.id"]
	});
	
	PersonPanel.superclass.constructor.call(this, {
		title : "员工信息管理",
		sm : sm,
		stripeRows : true,
		loadMask : true,
		tbar : [{
			text : "创建员工账号",
			ref : "../addButton",
			iconCls : "user_add",
			handler : function(){
				addPersonWindow.show();
			}
		},{
			text : "删除员工账号",
			ref : "../deleteButton",
			disabled : true,
			iconCls : "user_delete",
			handler : remove
		},{
			text : "员工设置",
			ref : "../setButton",
			iconCls : "setting",
			disabled : true,
			handler : function(){
				var rec = this_panel.getSelectionModel().getSelected();
				settingPersonWindow.setData(object2Entity(rec.data,"person"));
				settingPersonWindow.show();
			}
		}],
		columns : [sm,
		   		{header : "员工编号",dataIndex : "id"}, 
		   		{header : "员工姓名",dataIndex : "name"},
		   		{header : "技术支持",dataIndex : "supportType"},
		   		{header : "部门经理",dataIndex : "manager.name"}],
   		viewConfig: {
   		        forceFit: true
   		},
		store : store
	});
};
Ext.extend(PersonPanel, Ext.grid.GridPanel);
var personPanel = new PersonPanel();